package top.bug.blog.controller.backend;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.bug.blog.annotation.Auth;
import top.bug.blog.common.Result;
import top.bug.blog.entity.dto.album.*;
import top.bug.blog.entity.dto.common.BatchRequest;
import top.bug.blog.entity.dto.common.OrderModRequest;
import top.bug.blog.entity.dto.common.SingleRequest;
import top.bug.blog.entity.po.Album;
import top.bug.blog.entity.po.AlbumPic;
import top.bug.blog.service.AlbumService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author <a href="https://github.com/jiusi66">九思.</a>
 * @email 10837907@qq.com
 * @from <a href="https://www.52bug.top">递归茶馆-www.52bug.top</a>
 * @description 后台-相册模块
 */
@Auth
@RestController
@Api(tags = "相册管理模块")
@RequestMapping("/albumApi")
public class AlbumController {
    @Resource
    private AlbumService albumService;

    @PostMapping("/getList")
    @ApiOperation("获取列表")
    public Result<Page<Album>> getList(@RequestBody AlbumQueryRequest queryRequest) {
        return Result.success(albumService.getList(queryRequest));
    }

    @PostMapping("/add")
    @ApiOperation("新增相册")
    public Result<Boolean> add(@RequestBody AlbumAddRequest addRequest) {
        return Result.success(albumService.add(addRequest));
    }

    @PostMapping("/edit")
    @ApiOperation("编辑相册")
    public Result<Boolean> edit(@RequestBody AlbumUpdateRequest updateRequest) {
        return Result.success(albumService.edit(updateRequest));
    }

    @PostMapping("/delete")
    @ApiOperation("批量删除相册")
    public Result<Boolean> delete(@RequestBody BatchRequest batchRequest) {
        return Result.success(albumService.delete(batchRequest));
    }

    @PostMapping("/editOrder")
    @ApiOperation("相册排序修改")
    public Result<Boolean> editOrder(@RequestBody OrderModRequest modRequest) {
        return Result.success(albumService.editOrder(modRequest));
    }

    @PostMapping("/uploadPic")
    @ApiOperation("相册图片上传")
    public Result<List<String>> uploadPic(AlbumUploadRequest uploadRequest) {
        return Result.success(albumService.uploadPic(uploadRequest));
    }

    @PostMapping("/renamePic")
    @ApiOperation("相册图片重命名")
    public Result<Void> renamePic(@RequestBody AlbumPicUpdateRequest updateRequest) {
        albumService.renamePic(updateRequest);
        return Result.success();
    }

    @PostMapping("/deletePic")
    @ApiOperation("相册图片删除")
    public Result<Boolean> deletePic(@RequestBody BatchRequest batchRequest) {
        return Result.success(albumService.deletePic(batchRequest));
    }

    @PostMapping("/getPicList")
    @ApiOperation("获取相册图片列表")
    public Result<List<AlbumPic>> getPicList(@RequestBody SingleRequest singleRequest) {
        return Result.success(albumService.getPicList(singleRequest));
    }

}